package com.wwdx.service.impl;

import com.google.common.collect.Maps;
import com.wwdx.model.WwdxVipProductModel;
import com.wwdx.service.WwdxVipProductServiceI;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liguoliang
 * @date 2017-10-25 17:38
 */
@Service
public class WwdxVipProductServiceImpl extends BaseServiceImpl<WwdxVipProductModel> implements WwdxVipProductServiceI{

    @Override
    public Long selectModelCount(WwdxVipProductModel model){
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(6);
        String hql = "select count(1) from WwdxVipProductModel\t"+getParams(model,params);
        return count(hql,params);
    }

    private String getParams(WwdxVipProductModel model, Map<String, Object> params){
        StringBuilder sb = new StringBuilder("where 1=1\n");
        Integer status = model.getStatus();
        if (status != null){
            sb.append("and status =:status\t");
            params.put("status",status);
        }
        return sb.toString();
    }

    @Override
    public List<WwdxVipProductModel> selectModelList(WwdxVipProductModel model, Integer page, Integer rows){
        Map<String, Object> params = Maps.newHashMapWithExpectedSize(6);
        String hql = "from WwdxVipProductModel\t"+getParams(model,params)+"\torder by sort desc";
        return find(hql,params,page,rows);
    }

    @Override
    public WwdxVipProductModel getByProductId(Long productId) {
        HashMap<String, Object> params = Maps.newHashMapWithExpectedSize(2);
        params.put("product_id",productId);
        return getByHql("from WwdxVipProductModel where product_id=:product_id",params);
    }
}